Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | ACADEMIC RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * PROJECT METADATA8 * -----------------------------------------------------------------------------9 * Project : UQO Éval10 * File : src/app/api/metre/pages/[id]/route.ts11 * Module : app12 * Repository : https://git.spboucher.ai/uqo-eval13 * Project Website : https://www.uqo-eval.app14 * Created : 2026-10-2815 * Last Modified : 2026-10-2816 *17 * =============================================================================18 * SOFTWARE MAINTAINER & AFFILIATION19 * =============================================================================20 *21 * Maintainer : Simon-Pierre Boucher22 * Position : Professor of Finance23 * Institution : Université du Québec en Outaouais (UQO)24 * Department : Département des sciences administratives25 * Website : https://spboucher.ai26 * Git : https://git.spboucher.ai27 *28 * Research Contact : research@spboucher.ai29 * Direct Contact : simon@spboucher.ai30 * Security/Admin : admin@spboucher.ai31 *32 * The affiliation is descriptive. It is not an institutional endorsement,33 * a license grant or a determination of ownership.34 *35 * =============================================================================36 * COPYRIGHT, AUTHORSHIP & DATA37 * =============================================================================38 *39 * Copyright (c) the author(s) of this work.40 * Ownership is not asserted by this notice; see the repository records.41 *42 * This header identifies the maintainer of the software. Scientific43 * authorship of any associated paper is stated in the paper itself and44 * is not changed by this notice. Datasets and third-party materials45 * remain the property of their respective owners and licensors.46 *47 * This file is governed by the applicable project license, copyright48 * notices, institutional agreements and relevant law.49 *50 * =============================================================================51 * LICENSE & MAINTENANCE52 * =============================================================================53 *54 * License : None specified (no license file in this repository)55 * Classification : Public56 *57 * =============================================================================58 * END OF SP BOUCHER SOURCE HEADER59 * =============================================================================60 */6162// UQO Éval — Métré : une page de plan — détail, renommage/niveau (PATCH), suppression (DELETE), actions (POST : duplicate | measure_all).63import { NextRequest, NextResponse } from "next/server";64import { HttpError, handle, readJson, requireProject, requireUser } from "@/lib/metre/auth";65import { deletePage, duplicatePage, getPage, listObjects, measurePage, renamePage } from "@/lib/metre/plans";6667export const runtime = "nodejs";6869function load(req: NextRequest, id: string, need: "read" | "write") {70 const ctx = requireUser(req, { limit: { key: "page", max: 300, windowMs: 60_000 } });71 const page = getPage(ctx.db, id); if (!page) throw new HttpError(404, "Page introuvable.");72 requireProject(ctx, page.projectId, need);73 return { ctx, page };74}7576export async function GET(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {77 return handle(async () => { const { id } = await params; const { ctx, page } = load(req, id, "read"); const { imagePath, ...rest } = page; void imagePath; return NextResponse.json({ page: rest, objects: listObjects(ctx.db, id) }); });78}79export async function PATCH(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {80 return handle(async () => { const { id } = await params; const { ctx } = load(req, id, "write"); const b = await readJson<{ label?: string; level?: string | null }>(req); renamePage(ctx, id, b); return NextResponse.json({ ok: true }); });81}82export async function DELETE(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {83 return handle(async () => { const { id } = await params; const { ctx } = load(req, id, "write"); deletePage(ctx, id); return NextResponse.json({ ok: true }); });84}85export async function POST(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {86 return handle(async () => {87 const { id } = await params; const { ctx } = load(req, id, "write");88 const b = await readJson<{ action?: string; label?: string; level?: string | null; withObjects?: boolean }>(req);89 if (b.action === "duplicate") return NextResponse.json({ page: await duplicatePage(ctx, id, { label: b.label, level: b.level, withObjects: b.withObjects }) }, { status: 201 });90 if (b.action === "measure_all") return NextResponse.json(measurePage(ctx, id));91 throw new HttpError(400, "action : duplicate | measure_all");92 });93}94